home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14885 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.4 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Visual C++ help needed!!!!(please)
  5. Date: Tue, 02 Apr 1996 10:29:04 -0500
  6. Organization: Datalytics, Inc
  7. Message-ID: <316147C0.3E39@datalytics.com>
  8. References: <4jn1cn$7vo@crash.microserve.net> <4jnb8f$18u8@mule2.mindspring.com> <4jph92$fq9@bilbo.nask.org.pl>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. Grzegorz (FLS) wrote:
  16. > rudd@mindspring.com (Justin Rudd) wrote:
  17. > >ada105@psu.edu (Alexander Achey) wrote:
  18. > >>      I'm attempting to write a Visual C++ program in which I am making it
  19. > >>come up with schedules of college courses.  I use a modal dialog box
  20. > >>to get some information from the user and then I need to have it put
  21. > >>this data somewhere I can use it after the box is closed.  I tried
  22. > >>putting the variables under the public part of the document class, but
  23. > >>I can't seem to use the GetDocument() function from the dialog box.
  24. > >>Is there any other way to get access to the document's member
  25. > >>functions or is there a better way to do this?  i tried declaring this
  26. > >>as a global variable, but I really don't want to do that.  Besides, I
  27. > >>keep getign redinifition errors when I do that.  I'd really
  28. > >>apprecitate it if anyone could give me any kind of help.
  29. > >In your dialog class have a member function that accepts a pointer to
  30. > >a CDocument.
  31. > >void CMyDialog::SetDocPtr(CMyDoc* pDoc)
  32. > >{
  33. > >       m_pDoc = pDoc;
  34. > >}
  35. > I do not think, that declaring <SetDocPtr()> method is a good solution
  36. > (however it is not bad anyway ;)).
  37. > The solution, is to use local (public) members in CMyDialog dialog.
  38. > For example
  39. > class CMyDialog : public CDialog
  40. > {
  41. > ....
  42. > public: // input/outpu members
  43. >     int m_int_var ;
  44. >     CString m_string_var ;
  45. >     // ... etc. Sorry for members names.
  46. > }
  47. > When you want to use CMyDialog, you can do:
  48. > CMyDoc::OnEditMyDialog()
  49. > {
  50. >  CMyDialog dlg ;
  51. >     if ( dlg.DoModal() == IDOK )
  52. >     {
  53. >         // do something with dlg.m_int_var
  54. >         // do something with dlg.m_string_var
  55. >         // for example:
  56. >         m_doc_int_var = dlg.m_int_var ;
  57. >         m_doc_string_var = dlg.m_string_var ;
  58. >     }
  59. > }
  60. > This will work, and it is close to what you want, but it 
  61. perpetuates Microsoft's poor C++ programming.  The problem is 
  62. the use of public dms.  This is never a good idea, unless you 
  63. declare a struct and make it obvious that you're not 
  64. encapsulating data.
  65.  
  66. The better approach is to capture the desired data in another 
  67. class (or struct) and ask the dialog class to populate it.  That 
  68. way, you have a standard collection of the data between the 
  69. dialog and the document classes.  The dialog is free to store 
  70. the information anyway it sees fit, including in an object of 
  71. that class (or struct).
  72.  
  73. The idea is to call a member function of the dialog object and 
  74. have it return an object (struct) of that new type, or pass one 
  75. into the mf by reference for it to populate.  The dialog's 
  76. representation is completely encapsulated (unless you use MFC's 
  77. DDX functionality), and can change without affecting the code 
  78. using it.
  79.  
  80. Your document class can now manage an object (struct) of this 
  81. new type or, if desireable, use it to populate other dms or 
  82. objects.
  83.  
  84. -- 
  85. Robert Stewart        | My opinions are usually my own.
  86. Datalytics, Inc.    | stew@datalytics.com
  87.